package cn.shengchao.examstar.rpc.base;

import lombok.Data;

import java.io.Serializable;

/**
 * @program: examstarapi
 * @description: 公共的调用结果返回(以便返回异常时交互消息）
 * @author: Xiong weiqiang
 * @create: 2025-03-30 16:14
 */
@Data
public class TransResult<T> implements Serializable {
    private Boolean success;
    private String message;
    private T data;
    public static <T> TransResult<T> success(){
        TransResult<T> transResult = new TransResult<>();
        transResult.setSuccess(true);
        return transResult;
    }
    /**
     * 成功也可以传递数据
     * @param data
     * @return
     */
    public static <T> TransResult<T> success(T data){
        TransResult<T> transResult = new TransResult<>();
        transResult.setSuccess(true);
        transResult.setData(data);
        return transResult;
    }
    /**
     * 成功也可以传递数据数据，不同的情况
     * @param data
     * @return
     */
    public static <T> TransResult<T> success(T data,String message){
        TransResult<T> transResult = new TransResult<>();
        transResult.setSuccess(true);
        transResult.setData(data);
        transResult.setMessage(message);
        return transResult;
    }
    public static <T> TransResult<T> fail(String message){
        TransResult<T> transResult = new TransResult<>();
        transResult.setSuccess(false);
        transResult.setMessage(message);
        return transResult;
    }
}